package com.gcosc.hly.codejava.controller;

import com.gcosc.hly.codejava.entity.Topic;
import com.gcosc.hly.codejava.filter.AuthRoot;
import com.gcosc.hly.codejava.params.QueryParams;
import com.gcosc.hly.codejava.result.Result;
import com.gcosc.hly.codejava.service.TopicService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/topic")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TopicController {

    private final TopicService topicService;

    @GetMapping("/{id}")
    public Result detail(@PathVariable int id){
        return Result.ok(topicService.detail(id));
    }

    @GetMapping("/list")
    public Result list(QueryParams params){
        return Result.ok(topicService.queryParams(params));
    }

    @PostMapping("/edit")
    @AuthRoot
    public Result edit(@RequestBody Topic topic){
        return Result.ok(topicService.edit(topic));
    }

    @PostMapping("/del/{ids}")
    @AuthRoot
    public Result del(@PathVariable String ids){
        topicService.dels(ids);
        return Result.ok();
    }

}
